home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr57 / mentc.zip / EVAL.C < prev    next >
C/C++ Source or Header  |  1993-06-01  |  35KB  |  1,388 lines

  1. /*    EVAL.C: Expresion evaluation functions for
  2.         MicroEMACS
  3.  
  4.     written 1986 by Daniel Lawrence             */
  5.  
  6. #include    <stdio.h>
  7. #include    "estruct.h"
  8. #include    "eproto.h"
  9. #include    "edef.h"
  10. #include    "elang.h"
  11. #include    "evar.h"
  12.  
  13. PASCAL NEAR varinit()    /* initialize the user variable list */
  14.  
  15. {
  16.     register int i;
  17.  
  18.     for (i=0; i < MAXVARS; i++)
  19.         uv[i].u_name[0] = 0;
  20.  
  21.     return (0);
  22. }
  23.  
  24. PASCAL NEAR varclean()    /* initialize the user variable list */
  25.  
  26. {
  27.     register int i;
  28.  
  29.     for (i=0; i < MAXVARS; i++)
  30.         if (uv[i].u_name[0] != 0)
  31.             free(uv[i].u_value);
  32.  
  33.     return (0);
  34. }
  35.  
  36. char *PASCAL NEAR gtfun(fname)    /* evaluate a function */
  37.  
  38. char *fname;        /* name of function to evaluate */
  39.  
  40. {
  41.     register int fnum;        /* index to function to eval */
  42.     register int arg;        /* value of some arguments */
  43.     char arg1[NSTRING];        /* value of first argument */
  44.     char arg2[NSTRING];        /* value of second argument */
  45.     char arg3[NSTRING];        /* value of third argument */
  46.     static char result[2 * NSTRING];    /* string result */
  47. #if    ENVFUNC
  48.     char *getenv();         /* get environment string */
  49. #endif
  50.  
  51.     /* look the function up in the function table */
  52.     fname[3] = 0;    /* only first 3 chars significant */
  53.     mklower(fname); /* and let it be upper or lower case */
  54.     fnum = binary(fname, funval, NFUNCS);
  55.  
  56.     /* return errorm on a bad reference */
  57.     if (fnum == -1)
  58.         return(errorm);
  59.  
  60.     /* if needed, retrieve the first argument */
  61.     if (funcs[fnum].f_type >= MONAMIC) {
  62.         if (macarg(arg1) != TRUE)
  63.             return(errorm);
  64.  
  65.         /* if needed, retrieve the second argument */
  66.         if (funcs[fnum].f_type >= DYNAMIC) {
  67.             if (macarg(arg2) != TRUE)
  68.                 return(errorm);
  69.  
  70.             /* if needed, retrieve the third argument */
  71.             if (funcs[fnum].f_type >= TRINAMIC)
  72.                 if (macarg(arg3) != TRUE)
  73.                     return(errorm);
  74.         }
  75.     }
  76.  
  77.  
  78.     /* and now evaluate it! */
  79.     switch (fnum) {
  80.         case UFADD:    return(int_asc(asc_int(arg1) + asc_int(arg2)));
  81.         case UFSUB:    return(int_asc(asc_int(arg1) - asc_int(arg2)));
  82.         case UFTIMES:    return(int_asc(asc_int(arg1) * asc_int(arg2)));
  83.         case UFDIV:    return(int_asc(asc_int(arg1) / asc_int(arg2)));
  84.         case UFMOD:    return(int_asc(asc_int(arg1) % asc_int(arg2)));
  85.         case UFNEG:    return(int_asc(-asc_int(arg1)));
  86.         case UFCAT:    strcpy(result, arg1);
  87.                 return(strcat(result, arg2));
  88.         case UFLEFT:    return(bytecopy(result, arg1, asc_int(arg2)));
  89.         case UFRIGHT:    arg = asc_int(arg2);
  90.                 if (arg > strlen(arg1))
  91.                     arg = strlen(arg1);
  92.                 return(strcpy(result,
  93.                     &arg1[strlen(arg1) - arg]));
  94.         case UFMID:    arg = asc_int(arg2);
  95.                 if (arg > strlen(arg1))
  96.                     arg = strlen(arg1);
  97.                 return(bytecopy(result, &arg1[arg-1],
  98.                     asc_int(arg3)));
  99.         case UFNOT:    return(ltos(stol(arg1) == FALSE));
  100.         case UFEQUAL:    return(ltos(asc_int(arg1) == asc_int(arg2)));
  101.         case UFLESS:    return(ltos(asc_int(arg1) < asc_int(arg2)));
  102.         case UFGREATER: return(ltos(asc_int(arg1) > asc_int(arg2)));
  103.         case UFGROUP:
  104.                 if ((arg = asc_int(arg1)) < 0 || arg >= MAXGROUPS)
  105.                     return(bytecopy(result, errorm, NSTRING * 2));
  106.                     
  107. #if    MAGIC
  108.                 return(bytecopy(result, fixnull(grpmatch[arg]),
  109.                      NSTRING * 2));
  110. #else
  111.                 if (arg == 0)
  112.                     bytecopy(result, patmatch, NSTRING * 2);
  113.                 else
  114.                     result[0] = '\0';
  115.                 return(result);
  116. #endif
  117.         case UFSEQUAL:    return(ltos(strcmp(arg1, arg2) == 0));
  118.         case UFSLESS:    return(ltos(strcmp(arg1, arg2) < 0));
  119.         case UFSGREAT:    return(ltos(strcmp(arg1, arg2) > 0));
  120.         case UFIND:    return(strcpy(result, fixnull(getval(arg1))));
  121.         case UFAND:    return(ltos(stol(arg1) && stol(arg2)));
  122.         case UFOR:    return(ltos(stol(arg1) || stol(arg2)));
  123.         case UFLENGTH:    return(int_asc(strlen(arg1)));
  124.         case UFUPPER:    return(mkupper(arg1));
  125.         case UFLOWER:    return(mklower(arg1));
  126.         case UFTRUTH:    return(ltos(asc_int(arg1) == 42));
  127.         case UFASCII:    return(int_asc((int)arg1[0]));
  128.         case UFCHR:    result[0] = asc_int(arg1);
  129.                 result[1] = 0;
  130.                 return(result);
  131.         case UFGTCMD:    cmdstr(getcmd(), result);
  132.                 return(result);
  133.         case UFGTKEY:    result[0] = tgetc();
  134.                 result[1] = 0;
  135.                 return(result);
  136.         case UFRND:    return(int_asc((ernd() % absv(asc_int(arg1))) + 1));
  137.         case UFABS:    return(int_asc(absv(asc_int(arg1))));
  138.         case UFSINDEX:    return(int_asc(sindex(arg1, arg2)));
  139.         case UFENV:
  140. #if    ENVFUNC
  141.                 return(fixnull(getenv(arg1)));
  142. #else
  143.                 return("");
  144. #endif
  145.         case UFBIND:    return(transbind(arg1));
  146.         case UFEXIST:    return(ltos(fexist(arg1)));
  147.         case UFFIND:
  148.                 return(fixnull(flook(arg1, TRUE)));
  149.         case UFBAND:    return(int_asc(asc_int(arg1) & asc_int(arg2)));
  150.         case UFBOR:    return(int_asc(asc_int(arg1) | asc_int(arg2)));
  151.         case UFBXOR:    return(int_asc(asc_int(arg1) ^ asc_int(arg2)));
  152.         case UFBNOT:    return(int_asc(~asc_int(arg1)));
  153.         case UFXLATE:    return(xlat(arg1, arg2, arg3));
  154.         case UFTRIM:    return(trimstr(arg1));
  155.         case UFSLOWER:    return(setlower(arg1, arg2), "");
  156.         case UFSUPPER:    return(setupper(arg1, arg2), "");
  157.          case UFISNUM:    return(ltos(is_num(arg1)));
  158.     }
  159.  
  160.     meexit(-11);    /* never should get here */
  161. }
  162.  
  163. char *PASCAL NEAR gtusr(vname)    /* look up a user var's value */
  164.  
  165. char *vname;        /* name of user variable to fetch */
  166.  
  167. {
  168.     register int vnum;    /* ordinal number of user var */
  169.     register char *vptr;    /* temp pointer to function value */
  170.  
  171.     /* limit comparisons to significant length */
  172.     if (strlen(vname) >= NVSIZE)    /* "%" counts, but is not passed */
  173.         vname[NVSIZE-1] = '\0';
  174.  
  175.     /* scan the list looking for the user var name */
  176.     for (vnum = 0; vnum < MAXVARS; vnum++) {
  177.         if (uv[vnum].u_name[0] == 0)
  178.             return(errorm);
  179.         if (strcmp(vname, uv[vnum].u_name) == 0) {
  180.             vptr = uv[vnum].u_value;
  181.             if (vptr)
  182.                 return(vptr);
  183.             else
  184.                 return(errorm);
  185.         }
  186.     }
  187.  
  188.     /* return errorm if we run off the end */
  189.     return(errorm);
  190. }
  191.  
  192. char *PASCAL NEAR funval(i)
  193.  
  194. int i;
  195.  
  196. {
  197.     return(funcs[i].f_name);
  198. }
  199.  
  200. char *PASCAL NEAR envval(i)
  201.  
  202. int i;
  203.  
  204. {
  205.     return(envars[i]);
  206. }
  207.  
  208. PASCAL NEAR binary(key, tval, tlength)
  209.  
  210. char *key;        /* key string to look for */
  211. char *(PASCAL NEAR *tval)();    /* ptr to function to fetch table value with */
  212. int tlength;        /* length of table to search */
  213.  
  214. {
  215.     int l, u;    /* lower and upper limits of binary search */
  216.     int i;        /* current search index */
  217.     int cresult;    /* result of comparison */
  218.  
  219.     /* set current search limit as entire list */
  220.     l = 0;
  221.     u = tlength - 1;
  222.  
  223.     /* get the midpoint! */
  224.     while (u >= l) {
  225.         i = (l + u) >> 1;
  226.  
  227.         /* do the comparison */
  228.         cresult = strcmp(key, (*tval)(i));
  229.         if (cresult == 0)
  230.             return(i);
  231.         if (cresult < 0)
  232.             u = i - 1;
  233.         else
  234.             l = i + 1;
  235.     }
  236.     return(-1);
  237. }
  238.  
  239. char *PASCAL NEAR gtenv(vname)
  240.  
  241. char *vname;        /* name of environment variable to retrieve */
  242.  
  243. {
  244.     register int vnum;    /* ordinal number of var refrenced */
  245.     static char result[2 * NSTRING];    /* string result */
  246.  
  247.     /* scan the list, looking for the referenced name */
  248.     vnum = binary(vname, envval, NEVARS);
  249.  
  250.     /* return errorm on a bad reference */
  251.     if (vnum == -1)
  252.         return(errorm);
  253.  
  254.     /* otherwise, fetch the appropriate value */
  255.     switch (vnum) {
  256.         case EVFILLCOL: return(int_asc(fillcol));
  257.         case EVPAGELEN: return(int_asc(term.t_nrow + 1));
  258.         case EVCURCOL:    return(int_asc(getccol(FALSE)));
  259.         case EVCURLINE: return(int_asc(getlinenum(curbp, curwp->w_dotp)));
  260.         case EVRAM:    return(int_asc((int)(envram / 1024l)));
  261.         case EVFLICKER: return(ltos(flickcode));
  262.         case EVCURWIDTH:return(int_asc(term.t_ncol));
  263.         case EVCBFLAGS: return(int_asc(curbp->b_flag));
  264.         case EVCBUFNAME:return(curbp->b_bname);
  265.         case EVCFNAME:    return(curbp->b_fname);
  266.         case EVSRES:    return(sres);
  267.         case EVDEBUG:    return(ltos(macbug));
  268.         case EVSTATUS:    return(ltos(cmdstatus));
  269.         case EVPALETTE: return(palstr);
  270.         case EVASAVE:    return(int_asc(gasave));
  271.         case EVACOUNT:    return(int_asc(gacount));
  272.         case EVLASTKEY: return(int_asc(lastkey));
  273.         case EVCURCHAR:
  274.             return(curwp->w_dotp->l_used ==
  275.                     curwp->w_doto ? int_asc('\r') :
  276.                 int_asc(lgetc(curwp->w_dotp, curwp->w_doto)));
  277.         case EVDISCMD:    return(ltos(discmd));
  278.         case EVVERSION: return(VERSION);
  279.         case EVPROGNAME:return(PROGNAME);
  280.         case EVLANG:    return(LANGUAGE);
  281.         case EVSEED:    return(int_asc(seed));
  282.         case EVDISINP:    return(ltos(disinp));
  283.         case EVWLINE:    return(int_asc(curwp->w_ntrows));
  284.         case EVCWLINE:    return(int_asc(getwpos()));
  285.         case EVTARGET:    saveflag = lastflag;
  286.                 return(int_asc(curgoal));
  287.         case EVSEARCH:    return(pat);
  288.         case EVTIME:    return(timeset());
  289.         case EVREPLACE: return(rpat);
  290.         case EVMATCH:    return(fixnull(patmatch));
  291.         case EVKILL:    return(getkill());
  292.         case EVREGION:    return(getreg(result));
  293.         case EVCMODE:    return(int_asc(curbp->b_mode));
  294.         case EVGMODE:    return(int_asc(gmode));
  295.         case EVTPAUSE:    return(int_asc(term.t_pause));
  296.         case EVPENDING:
  297. #if    TYPEAH
  298.                 return(ltos(typahead()));
  299. #else
  300.                 return(falsem);
  301. #endif
  302.         case EVLWIDTH:    return(int_asc(llength(curwp->w_dotp)));
  303.         case EVLINE:    return(getctext());
  304.         case EVGFLAGS:    return(int_asc(gflags));
  305.         case EVRVAL:    return(int_asc(rval));
  306.         case EVREADHK:    return(fixnull(getfname(&readhook)));
  307.         case EVWRAPHK:    return(fixnull(getfname(&wraphook)));
  308.         case EVCMDHK:    return(fixnull(getfname(&cmdhook)));
  309.         case EVXPOS:    return(int_asc(xpos));
  310.         case EVYPOS:    return(int_asc(ypos));
  311.         case EVSTERM:    cmdstr(sterm, result);
  312.                 return(result);
  313.         case EVMODEFLAG:return(ltos(modeflag));
  314.         case EVSSCROLL: return(ltos(sscroll));
  315.         case EVLASTMESG:return(lastmesg);
  316.         case EVHARDTAB: return(int_asc(tabsize));
  317.         case EVSOFTTAB: return(int_asc(stabsize));
  318.         case EVSSAVE:    return(ltos(ssave));
  319.         case EVFCOL:    return(int_asc(curwp->w_fcol));
  320.         case EVHSCROLL: return(ltos(hscroll));
  321.         case EVHJUMP:    return(int_asc(hjump));
  322.         case EVBUFHOOK: return(fixnull(getfname(&bufhook)));
  323.         case EVEXBHOOK: return(fixnull(getfname(&exbhook)));
  324.         case EVWRITEHK: return(fixnull(getfname(&writehook)));
  325.         case EVDIAGFLAG:return(ltos(diagflag));
  326.         case EVMSFLAG:    return(ltos(mouseflag));
  327.         case EVOCRYPT:    return(ltos(oldcrypt));
  328.         case EVSEARCHPNT:    return(int_asc(searchtype));
  329.         case EVDISPHIGH:return(ltos(disphigh));
  330.         case EVLTERM:    return(lterm);
  331.         case EVPARALEAD:return(paralead);
  332.         case EVFMTLEAD:    return(fmtlead);
  333.         case EVWCHARS:    return(getwlist(result));
  334.         case EVPOPFLAG: return(ltos(popflag));
  335.         case EVYANKFLAG:    return(ltos(yankflag));
  336.         case EVSCRNAME:    return(first_screen->s_screen_name);
  337.         case EVCURWIND: return(int_asc(getcwnum()));
  338.         case EVNUMWIND: return(int_asc(gettwnum()));
  339.         case EVORGCOL:    return(int_asc(term.t_colorg));
  340.         case EVORGROW:    return(int_asc(term.t_roworg));
  341.         case EVDESKCLR:    return(cname[deskcolor]);
  342.     }
  343.     meexit(-12);    /* again, we should never get here */
  344. }
  345.  
  346. char *PASCAL NEAR fixnull(s)    /* Don't return NULL pointers! */
  347.  
  348. char *s;
  349.  
  350. {
  351.     if (s == NULL)
  352.         return("");
  353.     else
  354.         return(s);
  355. }
  356.  
  357. /* return some of the contents of the kill buffer */
  358.  
  359. char *PASCAL NEAR getkill()
  360.  
  361. {
  362.     register int size;    /* max number of chars left to return */
  363.     register char *sp;    /* ptr into KILL block data chunk */
  364.     register char *vp;    /* ptr into return value */
  365.     KILL *kptr;        /* ptr to the current KILL block */
  366.     int counter;        /* index into data chunk */
  367.     static char value[NSTRING];    /* temp buffer for value */
  368.  
  369.     /* no kill buffer....just a null string */
  370.     if (kbufh == (KILL *)NULL) {
  371.         value[0] = 0;
  372.         return(value);
  373.     }
  374.  
  375.     /* set up the output buffer */
  376.     vp = value;
  377.     size = NSTRING - 1;
  378.  
  379.     /* backed up characters? */
  380.     if (kskip > 0) {
  381.         kptr = kbufh;
  382.         sp = &(kptr->d_chunk[kskip]);
  383.         counter = kskip;
  384.         while (counter++ < KBLOCK) {
  385.             *vp++ = *sp++;
  386.             if (--size == 0) {
  387.                 *vp = 0;
  388.                 return(value);
  389.             }
  390.         }
  391.         kptr = kptr->d_next;
  392.     } else {
  393.         kptr = kbufh;
  394.     }
  395.  
  396.     if (kptr != (KILL *)NULL) {
  397.         while (kptr != kbufp) {
  398.             sp = kptr->d_chunk;
  399.             for (counter = 0; counter < KBLOCK; counter++) {
  400.                 *vp++ = *sp++;
  401.                 if (--size == 0) {
  402.                     *vp = 0;
  403.                     return(value);
  404.                 }
  405.             }
  406.             kptr = kptr->d_next;
  407.         }
  408.         counter = kused;
  409.         sp = kptr->d_chunk;
  410.         while (counter--) {
  411.             *vp++ = *sp++;
  412.             if (--size == 0) {
  413.                 *vp = 0;
  414.                 return(value);
  415.             }
  416.         }
  417.     }
  418.     
  419.     /* and return the constructed value */
  420.     *vp = 0;
  421.     return(value);
  422. }
  423.  
  424. char *PASCAL NEAR trimstr(s)    /* trim whitespace off the end of a string */
  425.  
  426. char *s;    /* string to trim */
  427.  
  428. {
  429.     char *sp;    /* backward index */
  430.  
  431.     sp = s + strlen(s) - 1;
  432.     while ((sp >= s) && (*sp == ' ' || *sp == '\t'))
  433.         --sp;
  434.     *(sp+1) = 0;
  435.     return(s);
  436. }
  437.  
  438. int PASCAL NEAR setvar(f, n)        /* set a variable */
  439.  
  440. int f;        /* default flag */
  441. int n;        /* numeric arg (can overide prompted value) */
  442.  
  443. {
  444.     register int status;    /* status return */
  445.     VDESC vd;        /* variable num/type */
  446.     char var[NVSIZE+1];    /* name of variable to fetch */
  447.     char value[NSTRING];    /* value to set variable to */
  448.  
  449.     /* first get the variable to set.. */
  450.     if (clexec == FALSE) {
  451.         status = mlreply(TEXT51, &var[0], NVSIZE+1);
  452. /*                 "Variable to set: " */
  453.         if (status != TRUE)
  454.             return(status);
  455.     } else {    /* macro line argument */
  456.         /* grab token and skip it */
  457.         execstr = token(execstr, var, NVSIZE + 1);
  458.     }
  459.  
  460.     /* check the legality and find the var */
  461.     findvar(var, &vd, NVSIZE + 1);
  462.         
  463.     /* if its not legal....bitch */
  464.     if (vd.v_type == -1) {
  465.         mlwrite(TEXT52, var);
  466. /*            "%%No such variable as '%s'" */
  467.         return(FALSE);
  468.     }
  469.  
  470.     /* get the value for that variable */
  471.     if (f == TRUE)
  472.         strcpy(value, int_asc(n));
  473.     else {
  474.         status = mlreply(TEXT53, &value[0], NSTRING);
  475. /*                 "Value: " */
  476.         if (status == ABORT)
  477.             return(status);
  478.     }
  479.  
  480.     /* and set the appropriate value */
  481.     status = svar(&vd, value);
  482.  
  483. #if    DEBUGM
  484.     /* if $debug == TRUE, every assignment will echo a statment to
  485.        that effect here. */
  486.         
  487.     if (macbug && (strcmp(var, "%track") != 0)) {
  488.         strcpy(outline, "(((");
  489.  
  490.         strcat(outline, var);
  491.         strcat(outline, " <- ");
  492.  
  493.         /* and lastly the value we tried to assign */
  494.         strcat(outline, value);
  495.         strcat(outline, ")))");
  496.  
  497.         /* expand '%' to "%%" so mlwrite wont bitch */
  498.         makelit(outline);
  499.  
  500.         /* write out the debug line */
  501.         mlforce(outline);
  502.         update(TRUE);
  503.  
  504.         /* and get the keystroke to hold the output */
  505.         if (getkey() == abortc) {
  506.             mlforce(TEXT54);
  507. /*                "[Macro aborted]" */
  508.             status = FALSE;
  509.         }
  510.     }
  511. #endif
  512.  
  513.     /* and return it */
  514.     return(status);
  515. }
  516.  
  517. PASCAL NEAR findvar(var, vd, size)    /* find a variables type and name */
  518.  
  519. char *var;    /* name of var to get */
  520. VDESC *vd;    /* structure to hold type and ptr */
  521. int size;    /* size of var array */
  522.  
  523. {
  524.     register int vnum;    /* subscript in varable arrays */
  525.     register int vtype;    /* type to return */
  526.  
  527. fvar:    vtype = -1;
  528.     switch (var[0]) {
  529.  
  530.         case '$': /* check for legal enviromnent var */
  531.             for (vnum = 0; vnum < NEVARS; vnum++)
  532.                 if (strcmp(&var[1], envars[vnum]) == 0) {
  533.                     vtype = TKENV;
  534.                     break;
  535.                 }
  536.             break;
  537.  
  538.         case '%': /* check for existing legal user variable */
  539.             for (vnum = 0; vnum < MAXVARS; vnum++)
  540.                 if (strcmp(&var[1], uv[vnum].u_name) == 0) {
  541.                     vtype = TKVAR;
  542.                     break;
  543.                 }
  544.             if (vnum < MAXVARS)
  545.                 break;
  546.  
  547.             /* create a new one??? */
  548.             for (vnum = 0; vnum < MAXVARS; vnum++)
  549.                 if (uv[vnum].u_name[0] == 0) {
  550.                     vtype = TKVAR;
  551.                     strcpy(uv[vnum].u_name, &var[1]);
  552.                     uv[vnum].u_value = NULL;
  553.                     break;
  554.                 }
  555.             break;
  556.  
  557.         case '&':    /* indirect operator? */
  558.             var[4] = 0;
  559.             if (strcmp(&var[1], "ind") == 0) {
  560.                 /* grab token, and eval it */
  561.                 execstr = token(execstr, var, size);
  562.                 strcpy(var, fixnull(getval(var)));
  563.                 goto fvar;
  564.             }
  565.     }
  566.  
  567.     /* return the results */
  568.     vd->v_num = vnum;
  569.     vd->v_type = vtype;
  570.  
  571.     return (0);
  572. }
  573.  
  574. int PASCAL NEAR svar(var, value)    /* set a variable */
  575.  
  576. VDESC *var;    /* variable to set */
  577. char *value;    /* value to set to */
  578.  
  579. {
  580.     register int vnum;    /* ordinal number of var refrenced */
  581.     register int vtype;    /* type of variable to set */
  582.     register int status;    /* status return */
  583.     register int c;     /* translated character */
  584.     register char *sp;    /* scratch string pointer */
  585.  
  586.     /* simplify the vd structure (we are gonna look at it a lot) */
  587.     vnum = var->v_num;
  588.     vtype = var->v_type;
  589.  
  590.     /* and set the appropriate value */
  591.     status = TRUE;
  592.     switch (vtype) {
  593.     case TKVAR: /* set a user variable */
  594.         if (uv[vnum].u_value != NULL)
  595.             free(uv[vnum].u_value);
  596.         sp = malloc(strlen(value) + 1);
  597.         if (sp == NULL)
  598.             return(FALSE);
  599.         strcpy(sp, value);
  600.         uv[vnum].u_value = sp;
  601.         break;
  602.  
  603.     case TKENV: /* set an environment variable */
  604.         status = TRUE;    /* by default */
  605.         switch (vnum) {
  606.         case EVFILLCOL: fillcol = asc_int(value);
  607.                 break;
  608.         case EVPAGELEN: status = newsize(TRUE, asc_int(value));
  609.                 break;
  610.         case EVCURCOL:    status = setccol(asc_int(value));
  611.                 break;
  612.         case EVCURLINE: status = gotoline(TRUE, asc_int(value));
  613.                 break;
  614.         case EVRAM:    break;
  615.         case EVFLICKER: flickcode = stol(value);
  616.                 break;
  617.         case EVCURWIDTH:status = newwidth(TRUE, asc_int(value));
  618.                 break;
  619.         case EVCBFLAGS: curbp->b_flag = (curbp->b_flag & ~(BFCHG|BFINVS))
  620.                     | (asc_int(value) & (BFCHG|BFINVS));
  621.                 lchange(WFMODE);
  622.                 break;
  623.         case EVCBUFNAME:strcpy(curbp->b_bname, value);
  624.                 curwp->w_flag |= WFMODE;
  625.                 break;
  626.         case EVCFNAME:    strcpy(curbp->b_fname, value);
  627.                 curwp->w_flag |= WFMODE;
  628.                 break;
  629.         case EVSRES:    status = TTrez(value);
  630.                 break;
  631.         case EVDEBUG:    macbug = stol(value);
  632.                 break;
  633.         case EVSTATUS:    cmdstatus = stol(value);
  634.                 break;
  635.         case EVPALETTE: bytecopy(palstr, value, 48);
  636.                 spal(palstr);
  637.                 break;
  638.         case EVASAVE:    gasave = asc_int(value);
  639.                 break;
  640.         case EVACOUNT:    gacount = asc_int(value);
  641.                 break;
  642.         case EVLASTKEY: lastkey = asc_int(value);
  643.                 break;
  644.         case EVCURCHAR: ldelete(1L, FALSE);    /* delete 1 char */
  645.                 c = asc_int(value);
  646.                 if (c == '\r')
  647.                     lnewline();
  648.                 else
  649.                     linsert(1, (char)c);
  650.                 backchar(FALSE, 1);
  651.                 break;
  652.         case EVDISCMD:    discmd = stol(value);
  653.                 break;
  654.         case EVVERSION: break;
  655.         case EVPROGNAME:break;
  656.         case EVLANG:    break;
  657.         case EVSEED:    seed = asc_int(value);
  658.                 break;
  659.         case EVDISINP:    disinp = stol(value);
  660.                 break;
  661.         case EVWLINE:    status = resize(TRUE, asc_int(value));
  662.                 break;
  663.         case EVCWLINE:    status = forwline(TRUE,
  664.                         asc_int(value) - getwpos());
  665.                 break;
  666.         case EVTARGET:    curgoal = asc_int(value);
  667.                 thisflag = saveflag;
  668.                 break;
  669.         case EVSEARCH:    strcpy(pat, value);
  670.                 setjtable(); /* Set up fast search arrays  */
  671. #if    MAGIC
  672.                 mcclear();
  673. #endif
  674.                 break;
  675.         case EVTIME:    break;
  676.         case EVREPLACE: strcpy(rpat, value);
  677. #if    MAGIC
  678.                 rmcclear();
  679. #endif 
  680.                 break;
  681.         case EVMATCH:    break;
  682.         case EVKILL:    break;
  683.         case EVREGION:    break;
  684.         case EVCMODE:    curbp->b_mode = asc_int(value);
  685.                 curwp->w_flag |= WFMODE;
  686.                 break;
  687.         case EVGMODE:    gmode = asc_int(value);
  688.                 break;
  689.         case EVTPAUSE:    term.t_pause = asc_int(value);
  690.                 break;
  691.         case EVPENDING: break;
  692.         case EVLWIDTH:    break;
  693.         case EVLINE:    putctext(value);
  694.                 break;
  695.         case EVGFLAGS:    gflags = asc_int(value);
  696.                 break;
  697.         case EVRVAL:    break;
  698.         case EVREADHK:    setkey(&readhook, value);
  699.                 break;
  700.         case EVWRAPHK:    setkey(&wraphook, value);
  701.                 break;
  702.         case EVCMDHK:    setkey(&cmdhook, value);
  703.                 break;
  704.         case EVXPOS:    xpos = asc_int(value);
  705.                 break;
  706.         case EVYPOS:    ypos = asc_int(value);
  707.                 break;
  708.         case EVSTERM:    sterm = stock(value);
  709.                 break;
  710.         case EVMODEFLAG:modeflag = stol(value);
  711.                 upwind();
  712.                 break;
  713.         case EVSSCROLL: sscroll = stol(value);
  714.                 break;
  715.         case EVLASTMESG:strcpy(lastmesg, value);
  716.                 break;
  717.         case EVHARDTAB: tabsize = asc_int(value);
  718.                 upwind();
  719.                 break;
  720.         case EVSOFTTAB: stabsize = asc_int(value);
  721.                 upwind();
  722.                 break;
  723.         case EVSSAVE:    ssave = stol(value);
  724.                 break;
  725.         case EVFCOL:    curwp->w_fcol = asc_int(value);
  726.                 if (curwp->w_fcol < 0)
  727.                     curwp->w_fcol = 0;
  728.                 curwp->w_flag |= WFHARD | WFMODE;
  729.                 break;
  730.         case EVHSCROLL: hscroll = stol(value);
  731.                 lbound = 0;
  732.                 break;
  733.         case EVHJUMP:    hjump = asc_int(value);
  734.                 if (hjump < 1)
  735.                     hjump = 1;
  736.                 if (hjump > term.t_ncol - 1)
  737.                     hjump = term.t_ncol - 1;
  738.                 break;
  739.         case EVBUFHOOK: setkey(&bufhook, value);
  740.                 break;
  741.         case EVEXBHOOK: setkey(&exbhook, value);
  742.                 break;
  743.         case EVWRITEHK: setkey(&writehook, value);
  744.                 break;
  745.         case EVDIAGFLAG:diagflag = stol(value);
  746.                 break;
  747.         case EVMSFLAG:    mouseflag = stol(value);
  748.                 break;
  749.         case EVOCRYPT:    oldcrypt = stol(value);
  750.                 break;
  751.         case EVSEARCHPNT:    searchtype = asc_int(value);
  752.                 if (searchtype < SRNORM  || searchtype > SREND)
  753.                     searchtype = SRNORM;
  754.                 break;
  755.         case EVDISPHIGH:
  756.                 c = disphigh;
  757.                 disphigh = stol(value);
  758.                 if (c != disphigh)
  759.                     upwind();
  760.                 break;
  761.         case EVLTERM:    bytecopy(lterm, value, NSTRING);
  762.                 break;
  763.         case EVPARALEAD:bytecopy(paralead, value, NSTRING);
  764.                 break;
  765.         case EVFMTLEAD:    bytecopy(fmtlead, value, NSTRING);
  766.                 break;
  767.         case EVWCHARS:    setwlist(value);
  768.                 break;
  769.         case EVPOPFLAG: popflag = stol(value);
  770.                 break;
  771.         case EVYANKFLAG:    yankflag = stol(value);
  772.                 break;
  773.         case EVSCRNAME:    select_screen(lookup_screen(value), TRUE);
  774.                 break;
  775.         case EVCURWIND:    nextwind(TRUE, asc_int(value));
  776.                 break;
  777.         case EVNUMWIND:    break;
  778.         case EVORGCOL:    status = new_col_org(TRUE, asc_int(value));
  779.                 break;
  780.         case EVORGROW:    status = new_row_org(TRUE, asc_int(value));
  781.                 break;
  782.         case EVDESKCLR:    c = lookup_color(mkupper(value));
  783.                 if (c != -1) {
  784.                     deskcolor = c;
  785. #if    WINDOW_TEXT
  786.                     refresh_screen(first_screen);
  787. #endif
  788.                 }
  789.                 break;
  790.         }
  791.         break;
  792.     }
  793.     return(status);
  794. }
  795.  
  796. /*    asc_int:    ascii string to integer......This is too
  797.         inconsistant to use the system's    */
  798.  
  799. int PASCAL NEAR asc_int(st)
  800.  
  801. char *st;
  802.  
  803. {
  804.     int result;    /* resulting number */
  805.     int sign;    /* sign of resulting number */
  806.     char c;     /* current char being examined */
  807.  
  808.     result = 0;
  809.     sign = 1;
  810.  
  811.     /* skip preceding whitespace */
  812.     while (*st == ' ' || *st == '\t')
  813.         ++st;
  814.  
  815.     /* check for sign */
  816.     if (*st == '-') {
  817.         sign = -1;
  818.         ++st;
  819.     }
  820.     if (*st == '+')
  821.         ++st;
  822.  
  823.     /* scan digits, build value */
  824.     while ((c = *st++))
  825.         if (c >= '0' && c <= '9')
  826.             result = result * 10 + c - '0';
  827.         else
  828.             break;
  829.  
  830.     return(result * sign);
  831. }
  832.  
  833. /*    int_asc:    integer to ascii string.......... This is too
  834.             inconsistant to use the system's    */
  835.  
  836. char *PASCAL NEAR int_asc(i)
  837.  
  838. int i;    /* integer to translate to a string */
  839.  
  840. {
  841.     register int digit;        /* current digit being used */
  842.     register char *sp;        /* pointer into result */
  843.     register int sign;        /* sign of resulting number */
  844.     static char result[INTWIDTH+1]; /* resulting string */
  845.  
  846.     /* record the sign...*/
  847.     sign = 1;
  848.     if (i < 0) {
  849.         sign = -1;
  850.         i = -i;
  851.     }
  852.  
  853.     /* and build the string (backwards!) */
  854.     sp = result + INTWIDTH;
  855.     *sp = 0;
  856.     do {
  857.         digit = i % 10;
  858.         *(--sp) = '0' + digit;    /* and install the new digit */
  859.         i = i / 10;
  860.     } while (i);
  861.  
  862.     /* and fix the sign */
  863.     if (sign == -1) {
  864.         *(--sp) = '-';    /* and install the minus sign */
  865.     }
  866.  
  867.     return(sp);
  868. }
  869.  
  870. int PASCAL NEAR gettyp(token)    /* find the type of a passed token */
  871.  
  872. char *token;    /* token to analyze */
  873.  
  874. {
  875.     register char c;    /* first char in token */
  876.  
  877.     /* grab the first char (this is all we need) */
  878.     c = *token;
  879.  
  880.     /* no blanks!!! */
  881.     if (c == 0)
  882.         return(TKNUL);
  883.  
  884.     /* a numeric literal? */
  885.     if (c >= '0' && c <= '9')
  886.         return(TKLIT);
  887.  
  888.     switch (c) {
  889.         case '"':    return(TKSTR);
  890.  
  891.         case '!':    return(TKDIR);
  892.         case '@':    return(TKARG);
  893.         case '#':    return(TKBUF);
  894.         case '$':    return(TKENV);
  895.         case '%':    return(TKVAR);
  896.         case '&':    return(TKFUN);
  897.         case '*':    return(TKLBL);
  898.  
  899.         default:    return(TKCMD);
  900.     }
  901. }
  902.  
  903. char *PASCAL NEAR getval(token) /* find the value of a token */
  904.  
  905. char *token;        /* token to evaluate */
  906.  
  907. {
  908.     register int status;    /* error return */
  909.     register BUFFER *bp;    /* temp buffer pointer */
  910.     register int blen;    /* length of buffer argument */
  911.     register int distmp;    /* temporary discmd flag */
  912.     static char buf[NSTRING];/* string buffer for some returns */
  913.  
  914.     switch (gettyp(token)) {
  915.         case TKNUL:    return("");
  916.  
  917.         case TKARG:    /* interactive argument */
  918.                 strcpy(token, fixnull(getval(&token[1])));
  919.                 distmp = discmd;    /* echo it always! */
  920.                 discmd = TRUE;
  921.                 status = getstring(token,
  922.                        buf, NSTRING, ctoec('\r'));
  923.                 discmd = distmp;
  924.                 if (status == ABORT)
  925.                     return(NULL);
  926.                 return(buf);
  927.  
  928.         case TKBUF:    /* buffer contents fetch */
  929.  
  930.                 /* grab the right buffer */
  931.                 strcpy(token, fixnull(getval(&token[1])));
  932.                 bp = bfind(token, FALSE, 0);
  933.                 if (bp == NULL)
  934.                     return(NULL);
  935.             
  936.                 /* if the buffer is displayed, get the window
  937.                    vars instead of the buffer vars */
  938.                 if (bp->b_nwnd > 0) {
  939.                     curbp->b_dotp = curwp->w_dotp;
  940.                     curbp->b_doto = curwp->w_doto;
  941.                 }
  942.  
  943.                 /* make sure we are not at the end */
  944.                 if (bp->b_linep == bp->b_dotp)
  945.                     return(NULL);
  946.             
  947.                 /* grab the line as an argument */
  948.                 blen = bp->b_dotp->l_used - bp->b_doto;
  949.                 if (blen > NSTRING)
  950.                     blen = NSTRING;
  951.                 bytecopy(buf, bp->b_dotp->l_text + bp->b_doto,
  952.                     blen);
  953.                 buf[blen] = 0;
  954.             
  955.                 /* and step the buffer's line ptr ahead a line */
  956.                 bp->b_dotp = bp->b_dotp->l_fp;
  957.                 bp->b_doto = 0;
  958.  
  959.                 /* if displayed buffer, reset window ptr vars*/
  960.                 if (bp->b_nwnd > 0) {
  961.                     curwp->w_dotp = curbp->b_dotp;
  962.                     curwp->w_doto = 0;
  963.                     curwp->w_flag |= WFMOVE;
  964.                 }
  965.  
  966.                 /* and return the spoils */
  967.                 return(buf);            
  968.  
  969.         case TKVAR:    return(gtusr(token+1));
  970.         case TKENV:    return(gtenv(token+1));
  971.         case TKFUN:    return(gtfun(token+1));
  972.         case TKDIR:    return(NULL);
  973.         case TKLBL:    return(NULL);
  974.         case TKLIT:    return(token);
  975.         case TKSTR:    return(token+1);
  976.         case TKCMD:    return(token);
  977.     }
  978. }
  979.  
  980. int PASCAL NEAR stol(val)    /* convert a string to a numeric logical */
  981.  
  982. char *val;    /* value to check for stol */
  983.  
  984. {
  985.     /* check for logical values */
  986.     if (val[0] == 'F')
  987.         return(FALSE);
  988.     if (val[0] == 'T')
  989.         return(TRUE);
  990.  
  991.     /* check for numeric truth (!= 0) */
  992.     return((asc_int(val) != 0));
  993. }
  994.  
  995. char *PASCAL NEAR ltos(val)    /* numeric logical to string logical */
  996.  
  997. int val;    /* value to translate */
  998.  
  999. {
  1000.     if (val)
  1001.         return(truem);
  1002.     else
  1003.         return(falsem);
  1004. }
  1005.  
  1006. char *PASCAL NEAR mkupper(str)    /* make a string upper case */
  1007.  
  1008. char *str;        /* string to upper case */
  1009.  
  1010. {
  1011.     char *sp;
  1012.  
  1013.     sp = str;
  1014.     while (*sp)
  1015.         uppercase(sp++);
  1016.     return(str);
  1017. }
  1018.  
  1019. char *PASCAL NEAR mklower(str)    /* make a string lower case */
  1020.  
  1021. char *str;        /* string to lower case */
  1022.  
  1023. {
  1024.     char *sp;
  1025.  
  1026.     sp = str;
  1027.     while (*sp)
  1028.         lowercase(sp++);
  1029.     return(str);
  1030. }
  1031.  
  1032. int PASCAL NEAR absv(x) /* take the absolute value of an integer */
  1033.  
  1034. int x;
  1035.  
  1036. {
  1037.     return(x < 0 ? -x : x);
  1038. }
  1039.  
  1040. int PASCAL NEAR ernd()    /* returns a random integer */
  1041.  
  1042. {
  1043.     seed = absv(seed * 1721 + 10007);
  1044.     return(seed);
  1045. }
  1046.  
  1047. int PASCAL NEAR sindex(source, pattern) /* find pattern within source */
  1048.  
  1049. char *source;    /* source string to search */
  1050. char *pattern;    /* string to look for */
  1051.  
  1052. {
  1053.     char *sp;    /* ptr to current position to scan */
  1054.     char *csp;    /* ptr to source string during comparison */
  1055.     char *cp;    /* ptr to place to check for equality */
  1056.  
  1057.     /* scanning through the source string */
  1058.     sp = source;
  1059.     while (*sp) {
  1060.         /* scan through the pattern */
  1061.         cp = pattern;
  1062.         csp = sp;
  1063.         while (*cp) {
  1064.             if (!eq(*cp, *csp))
  1065.                 break;
  1066.             ++cp;
  1067.             ++csp;
  1068.         }
  1069.  
  1070.         /* was it a match? */
  1071.         if (*cp == 0)
  1072.             return((int)(sp - source) + 1);
  1073.         ++sp;
  1074.     }
  1075.  
  1076.     /* no match at all.. */
  1077.     return(0);
  1078. }
  1079.  
  1080. /*    Filter a string through a translation table    */
  1081.  
  1082. char *PASCAL NEAR xlat(source, lookup, trans)
  1083.  
  1084. char *source;    /* string to filter */
  1085. char *lookup;    /* characters to translate */
  1086. char *trans;    /* resulting translated characters */
  1087.  
  1088. {
  1089.     register char *sp;    /* pointer into source table */
  1090.     register char *lp;    /* pointer into lookup table */
  1091.     register char *rp;    /* pointer into result */
  1092.     static char result[NSTRING];    /* temporary result */
  1093.  
  1094.     /* scan source string */
  1095.     sp = source;
  1096.     rp = result;
  1097.     while (*sp) {
  1098.         /* scan lookup table for a match */
  1099.         lp = lookup;
  1100.         while (*lp) {
  1101.             if (*sp == *lp) {
  1102.                 *rp++ = trans[lp - lookup];
  1103.                 goto xnext;
  1104.             }
  1105.             ++lp;
  1106.         }
  1107.  
  1108.         /* no match, copy in the source char untranslated */
  1109.         *rp++ = *sp;
  1110.  
  1111. xnext:        ++sp;
  1112.     }
  1113.  
  1114.     /* terminate and return the result */
  1115.     *rp = 0;
  1116.     return(result);
  1117. }
  1118.  
  1119. /*    setwlist:    Set an alternative list of character to be
  1120.             considered "in a word */
  1121.  
  1122. PASCAL NEAR setwlist(wclist)
  1123.  
  1124. char *wclist;    /* list of characters to consider "in a word" */
  1125.  
  1126. {
  1127.     register int index;
  1128.  
  1129.     /* if we are turning this facility off, just flag so */
  1130.     if (wclist == NULL || *wclist == 0) {
  1131.         wlflag = FALSE;
  1132.         return (0);
  1133.     }
  1134.  
  1135.     /* first clear the table */
  1136.     for (index = 0; index < 256; index++)
  1137.         wordlist[index] = FALSE;
  1138.  
  1139.     /* and for each character in the new value, set that element
  1140.        of the word character list */
  1141.     while (*wclist)
  1142.         wordlist[*wclist++] = TRUE;
  1143.     wlflag = TRUE;
  1144.  
  1145.     return (0);
  1146. }
  1147.  
  1148. /*    getwlist:    place in a buffer a list of characters
  1149.             considered "in a word"            */
  1150.  
  1151. char *PASCAL NEAR getwlist(buf)
  1152.  
  1153. char *buf;    /* buffer to place list of characters */
  1154.  
  1155. {
  1156.     register int index;
  1157.     register char *sp;
  1158.  
  1159.     /* if we are defaulting to a standard word char list... */
  1160.     if (wlflag == FALSE)
  1161.         return("");
  1162.  
  1163.     /* build the string of characters in the return buffer */
  1164.     sp = buf;
  1165.     for (index = 0; index < 256; index++)
  1166.         if (wordlist[index])
  1167.             *sp++ = index;
  1168.     *sp = 0;
  1169.     return(buf);
  1170. }
  1171.  
  1172. /*    is_num:    ascii string is integer......This is too
  1173.         inconsistant to use the system's    */
  1174.  
  1175. int PASCAL NEAR is_num(st)
  1176.  
  1177. char *st;
  1178.  
  1179. {
  1180.     int period_flag;    /* have we seen a period yet? */
  1181.  
  1182.     /* skip preceding whitespace */
  1183.     while (*st == ' ' || *st == '\t')
  1184.         ++st;
  1185.  
  1186.     /* check for sign */
  1187.     if ((*st == '-') || (*st == '+'))
  1188.         ++st;
  1189.  
  1190.     /* scan digits */
  1191.     period_flag = FALSE;
  1192.     while ((*st >= '0') && (*st <= '9') ||
  1193.            (*st == '.' && period_flag == FALSE)) {
  1194.         if (*st == '.')
  1195.             period_flag = TRUE;
  1196.         st++;
  1197.     }
  1198.  
  1199.     /* scan rest of line for just white space */
  1200.     while (*st) {
  1201.         if ((*st != '\t') && (*st != ' '))
  1202.             return(FALSE);
  1203.         st++;
  1204.     }
  1205.     return(TRUE);
  1206. }
  1207.  
  1208. #if    DEBUGM
  1209. int PASCAL NEAR dispvar(f, n)        /* display a variable's value */
  1210.  
  1211. int f;        /* default flag */
  1212. int n;        /* numeric arg (can overide prompted value) */
  1213.  
  1214. {
  1215.     register int status;    /* status return */
  1216.     VDESC vd;        /* variable num/type */
  1217.     char var[NVSIZE+1];    /* name of variable to fetch */
  1218.  
  1219.     /* first get the variable to display.. */
  1220.     if (clexec == FALSE) {
  1221.         status = mlreply(TEXT55, &var[0], NVSIZE+1);
  1222. /*                 "Variable to display: " */
  1223.         if (status != TRUE)
  1224.             return(status);
  1225.     } else {    /* macro line argument */
  1226.         /* grab token and skip it */
  1227.         execstr = token(execstr, var, NVSIZE + 1);
  1228.     }
  1229.  
  1230.     /* check the legality and find the var */
  1231.     findvar(var, &vd, NVSIZE + 1);
  1232.         
  1233.     /* if its not legal....bitch */
  1234.     if (vd.v_type == -1) {
  1235.         mlwrite(TEXT52, var);
  1236. /*            "%%No such variable as '%s'" */
  1237.         return(FALSE);
  1238.     }
  1239.  
  1240.     /* and display the value */
  1241.     strcpy(outline, var);
  1242.     strcat(outline, " = ");
  1243.  
  1244.     /* and lastly the current value */
  1245.     strcat(outline, fixnull(getval(var)));
  1246.  
  1247.     /* expand '%' to "%%" so mlwrite wont bitch */
  1248.     makelit(outline);
  1249.  
  1250.     /* write out the result */
  1251.     mlforce(outline);
  1252.     update(TRUE);
  1253.  
  1254.     /* and return */
  1255.     return(TRUE);
  1256. }
  1257.  
  1258. /*    describe-variables    Bring up a fake buffer and list the contents
  1259.                 of all the environment variables
  1260. */
  1261.  
  1262. PASCAL NEAR desvars(f, n)
  1263.  
  1264. int f,n;    /* prefix flag and argument */
  1265.  
  1266. {
  1267.     register WINDOW *wp;    /* scanning pointer to windows */
  1268.     register BUFFER *varbuf;/* buffer to put variable list into */
  1269.     register int uindex;    /* index into uvar table */
  1270.     char outseq[256];    /* output buffer for keystroke sequence */
  1271.  
  1272.     /* and get a buffer for it */
  1273.     varbuf = bfind(TEXT56, TRUE, 0);
  1274. /*           "Variable list" */
  1275.     if (varbuf == NULL || bclear(varbuf) == FALSE) {
  1276.         mlwrite(TEXT57);
  1277. /*            "Can not display variable list" */
  1278.         return(FALSE);
  1279.     }
  1280.  
  1281.     /* let us know this is in progress */
  1282.     mlwrite(TEXT58);
  1283. /*        "[Building variable list]" */
  1284.  
  1285.     /* build the environment variable list */
  1286.     for (uindex = 0; uindex < NEVARS; uindex++) {
  1287.  
  1288.         /* add in the environment variable name */
  1289.         strcpy(outseq, "$");
  1290.         strcat(outseq, envars[uindex]);
  1291.         pad(outseq, 14);
  1292.             
  1293.         /* add in the value */
  1294.         strcat(outseq, gtenv(envars[uindex]));
  1295.  
  1296.         /* and add it as a line into the buffer */
  1297.         if (addline(varbuf, outseq) != TRUE)
  1298.             return(FALSE);
  1299.     }
  1300.  
  1301.     if (addline(varbuf, "") != TRUE)
  1302.         return(FALSE);
  1303.  
  1304.     /* build the user variable list */
  1305.     for (uindex = 0; uindex < MAXVARS; uindex++) {
  1306.         if (uv[uindex].u_name[0] == 0)
  1307.             break;
  1308.  
  1309.         /* add in the user variable name */
  1310.         strcpy(outseq, "%");
  1311.         strcat(outseq, uv[uindex].u_name);
  1312.         pad(outseq, 14);
  1313.             
  1314.         /* add in the value */
  1315.         strcat(outseq, uv[uindex].u_value);
  1316.  
  1317.         /* and add it as a line into the buffer */
  1318.         if (addline(varbuf, outseq) != TRUE)
  1319.             return(FALSE);
  1320.     }
  1321.  
  1322.     /* display the list */
  1323.     wpopup(varbuf);
  1324.     mlerase();    /* clear the mode line */
  1325.     return(TRUE);
  1326. }
  1327.  
  1328. /*    describe-functions    Bring up a fake buffer and list the
  1329.                 names of all the functions
  1330. */
  1331.  
  1332. PASCAL NEAR desfunc(f, n)
  1333.  
  1334. int f,n;    /* prefix flag and argument */
  1335.  
  1336. {
  1337.     register WINDOW *wp;    /* scanning pointer to windows */
  1338.     register BUFFER *fncbuf;/* buffer to put function list into */
  1339.     register int uindex;    /* index into funcs table */
  1340.     char outseq[80];    /* output buffer for keystroke sequence */
  1341.  
  1342.     /* get a buffer for the function list */
  1343.     fncbuf = bfind(TEXT211, TRUE, 0);
  1344. /*           "Function list" */
  1345.     if (fncbuf == NULL || bclear(fncbuf) == FALSE) {
  1346.         mlwrite(TEXT212);
  1347. /*            "Can not display function list" */
  1348.         return(FALSE);
  1349.     }
  1350.  
  1351.     /* let us know this is in progress */
  1352.     mlwrite(TEXT213);
  1353. /*        "[Building function list]" */
  1354.  
  1355.     /* build the function list */
  1356.     for (uindex = 0; uindex < NFUNCS; uindex++) {
  1357.  
  1358.         /* add in the environment variable name */
  1359.         strcpy(outseq, "&");
  1360.         strcat(outseq, funcs[uindex].f_name);
  1361.  
  1362.         /* and add it as a line into the buffer */
  1363.         if (addline(fncbuf, outseq) != TRUE)
  1364.             return(FALSE);
  1365.     }
  1366.  
  1367.     if (addline(fncbuf, "") != TRUE)
  1368.         return(FALSE);
  1369.  
  1370.     /* display the list */
  1371.     wpopup(fncbuf);
  1372.     mlerase();    /* clear the mode line */
  1373.     return(TRUE);
  1374. }
  1375.  
  1376. pad(s, len)    /* pad a string to indicated length */
  1377.  
  1378. char *s;    /* string to add spaces to */
  1379. int len;    /* wanted length of string */
  1380.  
  1381. {
  1382.     while (strlen(s) < len) {
  1383.                 strcat(s, "          ");
  1384.         s[len] = 0;
  1385.     }
  1386. }
  1387. #endif
  1388.